import { Switch, Route, Redirect, } from "react-router-dom"
import Layout from "./layout"
import Login from "./page/login"
import NewsDetail from "./page/news/newsDetail"
import Error from "./page/error"
import "./common/style/global.css"
import { useEffect } from "react"
import { connect } from "react-redux"

function App(props) {

  const routes = [
    {
      key: 'login',
      path: "/login",
      component: Login
    },
    {
      key: 'newsDetail',
      path: "/newsDetail/:id",
      component: NewsDetail
    },
    {
      key: 'error',
      path: "/error",
      component: Error,
    },
    {
      key: 'layout',
      path: "/",
      component: Layout
    },
  ]

  // 模拟componentWillUnMount
  useEffect(() => {
    return () => {
    }
  }, [])


  return (
    <div className="App">
      <Switch >
        {routes.map(item => <Route key={item.key} {...item} exact={item.path === "/" ? false : true} />)}
        <Redirect to="/error" />
      </Switch>
    </div>
  );
}

export default App